package com.songlanyun.common.enums;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

import java.util.Objects;

/**

 * @author: Wzq
 * @create: 2020-03-02 14:33
 */
@Converter(autoApply = true)
public class PartnerTypeConverter implements AttributeConverter<OrderConstant.PaymentStatus, Integer> {

    @Override
    public Integer convertToDatabaseColumn(OrderConstant.PaymentStatus attribute) {
        return attribute.getCode();
    }

    @Override
    public OrderConstant.PaymentStatus convertToEntityAttribute(Integer dbData) {
        for (OrderConstant.PaymentStatus e : OrderConstant.PaymentStatus.values()) {
            if (Objects.equals(e.getCode(), dbData)) return e;
        }
        return null;
    }

}
